package com.qfedu.lc.user.controller;


import com.qfedu.lc.common.param.UserAdd;
import com.qfedu.lc.common.param.UserLogin;
import com.qfedu.lc.common.vo.R;
import com.qfedu.lc.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 1.用户表 前端控制器
 * </p>
 *
 * @author wgz
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 注册用户
     * /user/register
     */
    @PostMapping("/register")
    public R register(@RequestBody  UserAdd userAdd, HttpServletRequest request){

      return   userService.register(userAdd,request);

    }


    /**
     * 使用账号登录
     * @param userLogin
     * @param request
     * @return
     */
    @PostMapping("/loginpass")
    public R  loginPass(@RequestBody UserLogin userLogin, HttpServletRequest request){

        return userService.loginPass(userLogin,request);

    }

    /**
     * 退出登录
     *  删除token 相关的key
     * @return
     */
    @RequestMapping("/logout")
    public R logout( HttpServletRequest httpServletRequest){

        // 得到header中 的token
        String token = httpServletRequest.getHeader("Lctoken");
        return userService.logout(token);
    }
}

